/**
 * PreCreateResources
 * @ 精灵动画
 */
// 动画帧

class SpriteAnimation {
    constructor() {
        this.animations = {
            // 旋涡
            ani: [{
                delay: 0.1,
                duration: 0.6,
                from: { alpha: 0 },
                to: { alpha: 1 }
            }, {
                delay: 0.1,
                duration: 0.6,
                frames: this.getFrames('ani', 50)
            }, {
                delay: 0.7,
                duration: 0.2,
                to: { alpha: 0 }
            }, {
                delay: 0.7,
                duration: 0.2,
                frames: this.getFrames('ani', 50).reverse()
            }],
            // 女孩
            girl: [{
                delay: 0,
                duration: 1,
                frames: this.getFrames('girl', 62)
            }, {
                delay: 0,
                duration: 0.2,
                from: { y: -window.innerHeight },
                to: { y: window.innerHeight * 0.5 }
            }, {
                delay: 0.7,
                duration: 0.3,
                to: { y: window.innerHeight * 1.2 }
            }],
            // 飞机
            plane: [{
                duration: 2,
                frames: this.getFrames('plane', 25),
                infinite: true,
                frameRate: 15
            }, {
                delay: 0.8,
                duration: 0.2,
                from: { width: 0, height: 0, alpha: 0 }
            }]
        }
        // 物品
        for (let i = 1; i < 8; i += 1) {
            const delay = 0.25 + (i / 7 * 0.2)
            const x = i % 2 === 0 ? window.innerWidth * 0.65 : window.innerWidth * 0.35
            this.animations[`item${i}`] = [{
                delay,
                duration: 0.2,
                to: { x, y: -window.innerHeight * 0.2, width: 0, height: 0 }
            }, {
                duration: 0.5 + Math.random(),
                to: { yoyo: true, repeat: -1, rotation: 0.1 }
            }]
        }
        return this.animations
    }
    getFrames(key, n, start = 0) {
        const frames = []
        for (let i = start; i < n + start; i += 1) {
            frames.push(`${key}${i}`)
        }
        return frames
    }
}

export default new SpriteAnimation()